package com.ruoyi.flowable.listener.move;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.equ.domain.EquMove;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 移动-4监听
 */
@Slf4j
@Component("moveListener_4")
public class MoveListener_4 implements ExecutionListener {
    private static final ObjectMapper objectMapper = new ObjectMapper();

    @Override
    public void notify(DelegateExecution execution) {
        try {
            EquMove equMove = execution.getVariable("equMove", EquMove.class);
            String executeInfoStr = equMove.getExecuteInfo();
            Map<String, Object> executeInfoMap = objectMapper.readValue(executeInfoStr, new TypeReference<Map<String, Object>>() {});

            HashMap<String, Object> dataMap = new HashMap<>();
            dataMap.put("核对设备台账，确认移动是否合规", execution.getVariable("flag4", String.class));
            dataMap.put("具体情况", execution.getVariable("detailInfo4", String.class));
            executeInfoMap.put("资产管理部门审批", dataMap);
            String executeInfo = objectMapper.writeValueAsString(executeInfoMap);

            equMove.setExecuteInfo(executeInfo);
            execution.setVariable("equMove", equMove);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
    }
}
